starter.controller('loginPageController', ['$scope','$state', '$ionicHistory', '$ionicPopup', '$ionicLoading', '$http', '$rootScope' ,function($scope, $state, $ionicHistory, $ionicPopup, $ionicLoading,$http, $rootScope,  $cordovaFile, $cordovaFileTransfer) {
	var WINDOWS_BASE_URI = 'http://192.168.43.20:9090/spring-security-basic-auth/';
	var AWS_BASE_URI = 'http://ec2-13-126-78-43.ap-south-1.compute.amazonaws.com:5001/app/aws/';
	var USE_THIS_URI = AWS_BASE_URI;
    $scope.user={};
    $scope.response;
    $scope.isdisable=false;
    $scope.$on('$ionicView.enter', function(ev) {
        $scope.user.email="";       
        $scope.user.password="";        
    });
    if($scope.user.email=="" || $scope.user.password==""){
        $scope.isdisable=true;
    }
    
    $scope.authenticate = function() {
        $ionicLoading.show({
            template: '<ion-spinner></ion-spinner><br/>Signing In....'
        });
        debugger;
        $http({
            method: 'GET',
            async: true,
            dataType: 'jsonp',
            headers: {
        'authorization': 'Basic Sm9objEyMzpwYXNzd29yZA=='
            },
            url: USE_THIS_URI + "user",
        }).then(function successCallback(response) {
            console.log(response);
            alert("sucesss");
            $ionicLoading.hide();
            $state.go("home");
        }, function errorCallback(response) {
            console.log(response);
            $ionicLoading.hide();
            var FetchErrorAlert = $ionicPopup.alert({
                title: 'Fetch error!',
                template: 'Unable to login',
            });
        });
  
      }

$scope.createnewuser=function()
{
    $scope.newuser={};
    $state.go("newUser");
    $scope.newuser.firstname="";
}

$scope.forgotpassword=function()
{
     $state.go("enteremail");
}

}]);